package org.ruanjj.removenodes;

import org.ruanjj.linkedlist.ListNode;

public class Solution {
    public ListNode removeNodes(ListNode head) {
        ListNode cur = new ListNode(-1);
        ListNode res = cur;
        if(head == null){
            return head;
        }
        ListNode tmp= removeNodes(head.next);
        int tmpVal = tmp==null?0:tmp.val;
        if(head.val >= tmpVal){
            cur.next = head;
            cur = cur.next;
            cur.next = tmp;
        }else{
            cur.next = tmp;
        }
        return res.next;
    }
}
